package com.training.admin.entity.search;

import java.util.Date;
import java.util.Map;

import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

/**
 *
 * @author Rockett
 *
 */
public class ProjectTraineeReportSearch extends ReportSearch {

    /** 学员编号 */
    private String traineeCode;
    
    /** 学员姓名 */
    private String traineeName;
    /** 学员邮箱 */
    private String traineeEmail;
    
    /** 项目名称 */
    private String projectName;
    
    /** 事业部*/
    private Long departmentId;
    
    /** 分类  */
    private Long firstCategoryId;

    private Long secondCategoryId;
    /**开始时间 从*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginDateFrom;
    /**结束时间 到*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDateTo;
    /**结束时间 从*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endDateFrom;
    /**开始时间 到*/
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date beginDateTo;

    /**
     * 二级分类名 （主要用于非人类项目）
     */
    private String secondCategoryName;
    

    private String complete;
    
    private QueryFilter filter;
    
    private QueryOrder order;

    /**
     * The default constructor
     */
    public ProjectTraineeReportSearch() {
        order = new QueryOrder("project.name", "asc");
    }
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {
    	
        if (filter == null || refresh) {
        	
            filter = new QueryFilter().addLike("trainee.name", traineeName)
					.addLike("trainee.code", traineeCode)
					.addLike("trainee.email", traineeEmail)
					.addEquals("project.department","id", departmentId)
					.addDateBetween("project.beginDate", beginDateFrom, beginDateTo)
					.addDateBetween("project.endDate", endDateFrom, endDateTo)
					.addEquals("project.firstCategory","id", firstCategoryId)
					.addEquals("project.secondCategory","id", secondCategoryId)
					.addLike("project.secondCategory.name", secondCategoryName)
					.addLike("project.name",projectName)
					;
            	if ("true".equalsIgnoreCase(this.complete)){
            		filter.addEquals("complete", true);
            	}else if ("false".equalsIgnoreCase(this.complete)){
            		filter.addEquals("complete", false);
            	}
        }
        
        return filter;
        
    }
    
	/*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM ProjectTrainee where disabled=false " + getPreparedFilter(false).clauseSentence() + order.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
    /**
	 * @return the firstCategoryId
	 */
	public Long getFirstCategoryId() {
		return firstCategoryId;
	}
	/**
	 * @param firstCategoryId the firstCategoryId to set
	 */
	public void setFirstCategoryId(Long firstCategoryId) {
		this.firstCategoryId = firstCategoryId;
	}
	/**
	 * @return the secondCategoryId
	 */
	public Long getSecondCategoryId() {
		return secondCategoryId;
	}
	/**
	 * @param secondCategoryId the secondCategoryId to set
	 */
	public void setSecondCategoryId(Long secondCategoryId) {
		this.secondCategoryId = secondCategoryId;
	}
	/**
	 * @return the beginDateFrom
	 */
	public Date getBeginDateFrom() {
		return beginDateFrom;
	}
	/**
	 * @param beginDateFrom the beginDateFrom to set
	 */
	public void setBeginDateFrom(Date beginDateFrom) {
		this.beginDateFrom = beginDateFrom;
	}
	/**
	 * @return the endDateTo
	 */
	public Date getEndDateTo() {
		return endDateTo;
	}
	/**
	 * @param endDateTo the endDateTo to set
	 */
	public void setEndDateTo(Date endDateTo) {
		this.endDateTo = endDateTo;
	}
	/**
	 * @return the endDateFrom
	 */
	public Date getEndDateFrom() {
		return endDateFrom;
	}
	/**
	 * @param endDateFrom the endDateFrom to set
	 */
	public void setEndDateFrom(Date endDateFrom) {
		this.endDateFrom = endDateFrom;
	}
	/**
	 * @return the beginDateTo
	 */
	public Date getBeginDateTo() {
		return beginDateTo;
	}
	/**
	 * @param beginDateTo the beginDateTo to set
	 */
	public void setBeginDateTo(Date beginDateTo) {
		this.beginDateTo = beginDateTo;
	}
	/**
	 * @return the complete
	 */
	public String getComplete() {
		return complete;
	}
	/**
	 * @param complete the complete to set
	 */
	public void setComplete(String complete) {
		this.complete = complete;
	}
	/**
	 * @return the projectName
	 */
	public String getProjectName() {
		return projectName;
	}
	/**
	 * @param projectName the projectName to set
	 */
	public void setProjectName(String projectName) {
		this.projectName = projectName;
	}

    

    /**
     * 
     * @return
     */
    public QueryFilter getFilter(){
        return getPreparedFilter(false);
    }
	/**
	 * @return the order
	 */
	public QueryOrder getOrder() {
		return order;
	}

	/**
	 * @return the departmentId
	 */
	public Long getDepartmentId() {
		return departmentId;
	}
	/**
	 * @param departmentId the departmentId to set
	 */
	public void setDepartmentId(Long departmentId) {
		this.departmentId = departmentId;
	}
	/**
	 * @return the traineeCode
	 */
	public String getTraineeCode() {
		return traineeCode;
	}
	/**
	 * @param traineeCode the traineeCode to set
	 */
	public void setTraineeCode(String traineeCode) {
		this.traineeCode = traineeCode;
	}
	/**
	 * @return the traineeName
	 */
	public String getTraineeName() {
		return traineeName;
	}
	/**
	 * @param traineeName the traineeName to set
	 */
	public void setTraineeName(String traineeName) {
		this.traineeName = traineeName;
	}
	/**
	 * @return the traineeEmail
	 */
	public String getTraineeEmail() {
		return traineeEmail;
	}
	/**
	 * @param traineeEmail the traineeEmail to set
	 */
	public void setTraineeEmail(String traineeEmail) {
		this.traineeEmail = traineeEmail;
	}
	/**
	 * @return the secondCategoryName
	 */
	public String getSecondCategoryName() {
		return secondCategoryName;
	}
	/**
	 * @param secondCategoryName the secondCategoryName to set
	 */
	public void setSecondCategoryName(String secondCategoryName) {
		this.secondCategoryName = secondCategoryName;
	}




}
